package com.tedu.egweibo.config;


import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@MapperScan("com.tedu.egweibo.mapper")
@EnableSwagger2WebMvc
public class Config {

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                // 配置api文档信息
                .apiInfo(apiInfo())
                // 扫描指定包下的接口
                .select().apis(RequestHandlerSelectors.basePackage("com.tedu.egweibo.controller"))
                // 扫描指定路径下的接口
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                // 项目标题
                .title("微博项目")
                // 项目描述
                .description("微博项目接口文档")
                // 版本号
                .version("1.0")
                // 联系人信息
                .contact(new Contact("yigei", "http://www.tedu.cn", "yigei@tedu.cn"))
                // 生成文档
                .build();
    }

}
